package com.gxjtkyy.datadistributer.writer.rdbms.service;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class KafkaCustomer {
 
    /**
     * 定义此消费者接收topics = "first"的消息，与controller中的topic对应上即可
     * @param records 变量代表消息本身，可以通过ConsumerRecord<?,?>类型的record变量来打印接收的消息的各种信息
     * 消费者开启批量消费数据后(kafka.listener.type: batch)，不能用单个实体类接收参数，而应该用list
     */
//    @KafkaListener(topics = "kafka_text_topic")
    public void userListener(List<ConsumerRecord<?,?>> records) {
        for (ConsumerRecord<?,?> record: records) {
            System.err.println("消费消息：topic: " + record.topic()
                    + "--> offset:" + record.offset()
                    + "msg: " + record.value());
        }
    }
}